/*
var machLength = function (name) {
    var m = '';
    $("input[name='" + name + "']").each(function () {
        m += $(this).val();
    });
    return m;
};
function stringToArray(string) {
    var myCars = [];
    for(var i = 1;i <= string.length; i++){
        myCars[i] = string.slice(i-1,i);
    }
    // 删除默认第一个
    myCars.splice(0,1);
    return myCars;
}
*/
$(function () {

    // 发送短信
    $('#sendMsgBtn').click(function () {
        sendMobileMsgCode("/uc/safe/pay_sms.html", '', '', '');
    });

    $(".password").bind(input_key,function () {
        var val = $(this).val().replace(/\b()/gi,'').replace(/[^\d]/gi,'').replace(/[^0-9]/g,'');
        $(this).val(val);
    });

    /**
     * TODO:AJAX 提交表单
     */
    $("#form").submit(function () {

        var self = $(this);
        var payPwd = /^[0-9]{6}$/;  // 支付密码
        var val = $('#password1').val();
        var val1 = $('#password2').val();
        if (!checkPhoneCode()) return false;
        if (!payPwd.test(val)) {
            layer.alert('请输入6位数字支付密码！',{icon : 2 , title : "温馨提醒"}, function (index) {
                layer.close(index);
                $('#password1').focus();
            });
            return false;
        }
        if (val != val1) {
            layer.alert('两次输入支付密码不一致！',{icon : 2 , title : "温馨提醒"}, function (index) {
                layer.close(index);
                $('#password2').focus();
            });
            return false;
        }
        ajax_post(self);
        layer.closeAll();
        return false;
    });

    $("#first_form").submit(function () {

        var self = $(this);
        var payPwd = /^[0-9]{6}$/;  // 支付密码
        var val = $('#password1').val();
        var val1 = $('#password2').val();
        if (!payPwd.test(val)) {
            layer.alert('请输入6位数字支付密码！',{icon : 2 , title : "温馨提醒"}, function (index) {
                layer.close(index);
                $('#password1').focus();
            });
            return false;
        }
        if (val != val1) {
            layer.alert('两次输入支付密码不一致！',{icon : 2 , title : "温馨提醒"}, function (index) {
                layer.close(index);
                $('#password2').focus();
            });
            return false;
        }
        ajax_post(self);
        layer.closeAll();
        return false;
    });

});